home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: actuary@nando.net (Bill McCarthy)
- Newsgroups: comp.lang.c
- Subject: Re: What should be returned?
- Date: 23 Jan 1996 06:08:22 GMT
- Organization: News & Observer Public Access
- Message-ID: <4e1u0m$smj@castle.nando.net>
- References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk> <tcpnntpd.16.1.17.17.34.44.2781597121.346998@the-fix.sos.on.ca>
- Reply-To: actuary@nando.net (Bill McCarthy)
- NNTP-Posting-Host: grail1017.nando.net
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <tcpnntpd.16.1.17.17.34.44.2781597121.346998@the-fix.sos.on.ca>,
- <verneb@the-fix.sos.on.ca> writes:
-
- >To: INT:phsung@cs.cuhk.hk
- >
- >Int:phsung@cs.cuhk.hk,
- >
- >I >Hi, all,
- >I >
- >I > It's said that the function main must return an integer value
- >I >but I just don't know what value should be returned. Also, if I quit
- >I >main by exit(), what's the use of the return value?
- >I >
- >
- > simply use return 0; and that will satisfy your compiler e.g.
- >
- > #include <stdio.h>
- > int main(void)
- > {
- > printf("This should work I think, I hope, I know it will!\n");
- > return 0;
- > }
- >
- > Main is asking for nothing so you return the same by 'return 0;'.
-
- That last statement may be interpreted by a beginner to mean that
- since main()'s arguments are "void" then you should return 0. Of
- course, main() is declared to return an int, so one must return one.
-
- Returning a 0 means the operating will receive a value indicating
- successful completion (it may be different from 0 and may even
- be something other than an integer).
-
- To the original poster, include <stdlib.h> and return EXIT_SUCCESS or
- return 0 for successful completion. Return EXIT_FAILURE if there is
- a failure. The same applies to exit().
-
- Bill McCarthy
- actuary@nando.net
- Wendell, NC USA
-